implicit TRUE and FALSE
The notion of TRUE and FALSE are implicit in many statements, including:
IF , IFZ , CASE , DO WHILE , DO UNTIL , LOOP WHILE , LOOP UNTIL .
The following examples illustrate the nature of TRUE and FALSE and how convenient they can
be.
a = 0 ' a is FALSE because its value
is zero
b = -3 ' b is TRUE because its value is non-zero
c = 2 ' c is TRUE because its value is non-zero
a$ = "" ' a$ is FALSE because it has no contents
b$ = "0" ' a$ is TRUE because it has contents
("0")
c$ = " " ' a$ is TRUE because it has contents ("
")
d$ = "\0" ' a$ is TRUE because it has contents (1 byte)
DIM a[] ' a[] is FALSE because it has no contents
DIM b[0] ' b[] is TRUE because it has contents
DIM c[1] ' c[] is TRUE because it has contents
DIM d$[7,] ' d$[] is TRUE because it has contents
'
' note: d$[0,] is FALSE because it has no contents
'
IF a THEN PRINT a ' Nothing
will print because a is FALSE
IF b THEN PRINT b '
"-3" will print because b is TRUE
IF c THEN PRINT c '
"2" will print because c is TRUE
IF a$ THEN PRINT "a$" ' Nothing will print
because a$ is FALSE
IF b$ THEN PRINT b$ ' "0" will
print because b$ is TRUE
IF c$ THEN PRINT "c$" ' "c$" will
print because c$ is TRUE
IF d$ THEN PRINT "d$" ' "d$" will
print because d$ is TRUE
IF a[] THEN PRINT "a[]" ' Nothing will print because
a[] is FALSE
IF b[] THEN PRINT "b[]" ' "b[]" will print
because b[] is TRUE
IF c[] THEN PRINT "c[]" ' "c[]" will print
because c[] is TRUE
IF d$[] THEN PRINT "d$[]" ' "d$[]" will print because
d$[] is TRUE
IF d$[1] THEN PRINT "YES" ' Nothing will print because d$[1] is
FALSE
'
DO WHILE b
' The loop will execute because b is TRUE
INC b
' b = b + 1
IF c THEN PRINT "hi" ' "hi" will
print because c is TRUE
LOOP WHILE a$
' The loop will
end because a$ is FALSE
'
SELECT CASE ALL TRUE ' Do all CASEs that are
true
CASE a: PRINT "a" '
Nothing will print because a is FALSE
CASE b: PRINT "b" '
"b" will print because b is TRUE
CASE a, b: PRINT "a, b" ' "a, b" will print
because b is TRUE
CASE a, a$: PRINT a, a$ ' Nothing will print because a and a$ are
FALSE
CASE a[]: PRINT "a[]" ' Nothing will print
because a[] is FALSE
CASE b[]: PRINT "b[]" ' "b[]"
will print because b is TRUE
CASE d$[]: PRINT "d$[]" ' "d$[]" will print
because d$ is TRUE
CASE d$[e]: PRINT d$[e] ' Nothing will print because d$[e] is
FALSE
END SELECT